/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author melchiorin
 */
class WorkingMemory {
	private List<Rule> rules = new ArrayList<Rule>()
	private Map<String, String> memory
	
	public void addRule(rule){
		if (!rules.contains(rule))
		{
			rules.add(rule)
			rule.conclusions.each{ key, value ->
				if(memory.get("${key}") == null){
					memory.put("${key}","${value}")				
				}
			}
		}
	}
	
	public String toString(){
		def string = ""
		rules.each{
			string += it.toString()
		}
		return string
	}
	
	public String getConclusions(){
		def con = ""
		rules.each{
			con += it.getConclusionsString()
		}
		return con;
	}
	
	public boolean isInMemory(Rule rule){
		return rules.contains(rule)
	}
	
	public String memoryToString(){
		String result = ""
		memory.each{
			k, v ->
				result += "${k}=${v},"					
		}
		return result
	}
	
	public boolean isInWorkingMemory(key, value){
		boolean result = false
		memory.each{
			k, v ->
				if( "${k}"=="${key}" && "${v}"=="${value}")
					result = true
		}
		return result
	}
}

